/**
 * <copyright>
 *
 * Copyright (c) 2011 Zeligsoft (2009) Limited
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   Zeligsoft (2009) Limited - Initial API and implementation
 *
 * </copyright>
 *
 */
package org.omg.deployment.components;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.context.PropertiesEditingContext;
import org.eclipse.emf.eef.runtime.impl.components.SinglePartPropertiesEditingComponent;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.omg.deployment.ComponentExternalPortEndpoint;
import org.omg.deployment.DeploymentPackage;
import org.omg.deployment.ExternalReferenceEndpoint;
import org.omg.deployment.PlanConnectionDescription;
import org.omg.deployment.PlanSubcomponentPortEndpoint;
import org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart;
import org.omg.deployment.parts.DeploymentViewsRepository;


/**
 * @author Toby McClean; Zeligsoft (2009) Limited
 * @generated
 */
public class PlanConnectionDescriptionConnectionEndsPropertiesEditionComponent extends SinglePartPropertiesEditingComponent {

	/**
	 * @generated
	 */
	
	public static String CONNECTIONENDS_PART = "ConnectionEnds"; //$NON-NLS-1$

	
	
	/**
   * Settings for ends ReferencesTable
   */
  protected ReferencesTableSettings endsSettings;



  /**
   * Settings for externalEnds ReferencesTable
   */
  protected ReferencesTableSettings externalEndsSettings;



  /**
   * Settings for externalRefs ReferencesTable
   */
  protected ReferencesTableSettings externalRefsSettings;



  /**
	 * Default constructor
	 * @generated
	 */
	public PlanConnectionDescriptionConnectionEndsPropertiesEditionComponent(PropertiesEditingContext editingContext, EObject planConnectionDescription, String editing_mode) {
    super(editingContext, planConnectionDescription, editing_mode);
    parts = new String[] { CONNECTIONENDS_PART };
    repositoryKey = DeploymentViewsRepository.class;
    partKey = DeploymentViewsRepository.ConnectionEnds.class;
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject, 
	 *      org.eclipse.emf.ecore.resource.ResourceSet)
	 * @generated
	 */
	public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
      editingPart.setContext(elt, allResource);
      final PlanConnectionDescription planConnectionDescription = (PlanConnectionDescription)elt;
      final ConnectionEndsPropertiesEditionPart connectionEndsPart = (ConnectionEndsPropertiesEditionPart)editingPart;
      // init values
      if (isAccessible(DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends)) {
        endsSettings = new ReferencesTableSettings(planConnectionDescription, DeploymentPackage.eINSTANCE.getPlanConnectionDescription_InternalEndpoint());
        connectionEndsPart.initEnds(endsSettings);
      }
      if (isAccessible(DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_)) {
        externalEndsSettings = new ReferencesTableSettings(planConnectionDescription, DeploymentPackage.eINSTANCE.getPlanConnectionDescription_ExternalEndpoint());
        connectionEndsPart.initExternalEndPoint(externalEndsSettings);
      }
      if (isAccessible(DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_)) {
        externalRefsSettings = new ReferencesTableSettings(planConnectionDescription, DeploymentPackage.eINSTANCE.getPlanConnectionDescription_ExternalReference());
        connectionEndsPart.initExternalReference(externalRefsSettings);
      }
      // init filters
      connectionEndsPart.addFilterToEnds(new ViewerFilter() {
      
          /**
           * {@inheritDoc}
           * 
           * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
           */
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return (element instanceof String && element.equals("")) || (element instanceof PlanSubcomponentPortEndpoint); //$NON-NLS-1$ 
          }
      
      });
      
      connectionEndsPart.addFilterToExternalEndPoint(new ViewerFilter() {
      
          /**
           * {@inheritDoc}
           * 
           * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
           */
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return (element instanceof String && element.equals("")) || (element instanceof ComponentExternalPortEndpoint); //$NON-NLS-1$ 
          }
      
      });
      
      connectionEndsPart.addFilterToExternalReference(new ViewerFilter() {
      
          /**
           * {@inheritDoc}
           * 
           * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
           */
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return (element instanceof String && element.equals("")) || (element instanceof ExternalReferenceEndpoint); //$NON-NLS-1$ 
          }
      
      });
      
      // init values for referenced views
      
      // init filters for referenced views
      
    }
    setInitializing(false);
  }



	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#associatedFeature(java.lang.Object)
	 */
	public EStructuralFeature associatedFeature(Object editorKey) {
		return super.associatedFeature(editorKey);
	}

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * @generated
	 */
	public void updateSemanticModel(final IPropertiesEditionEvent event) {
    PlanConnectionDescription planConnectionDescription = (PlanConnectionDescription)semanticObject;
  }

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updatePart(org.eclipse.emf.common.notify.Notification)
	 */
	public void updatePart(Notification msg) {
		if (editingPart.isVisible()) {	
			ConnectionEndsPropertiesEditionPart connectionEndsPart = (ConnectionEndsPropertiesEditionPart)editingPart;
			
		}
	}


	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * @generated
	 */
	public Diagnostic validateValue(IPropertiesEditionEvent event) {
    Diagnostic ret = Diagnostic.OK_INSTANCE;
    if (event.getNewValue() != null) {
      try {
      } catch (IllegalArgumentException iae) {
        ret = BasicDiagnostic.toDiagnostic(iae);
      } catch (WrappedException we) {
        ret = BasicDiagnostic.toDiagnostic(we);
      }
    }
    return ret;
  }

}
